package com.guohang.ESProject08;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {

  public static final String TABLE_NAME = "es_table01";
  
  public static final String COLUMN_CAPTURE = "_id";
  public static final String COLUMN_IMAGE = "image";
  public static final String COLUMN_TEXT = "text";
  public static final String COLUMN_SENSOR_TEMP = "sensor_temp";
  public static final String COLUMN_SENSOR_GSR = "sensor_gsr";
  public static final String COLUMN_SENSOR_HEARTRATE = "sensor_heartrate";
  public static final String COLUMN_SENSOR_SOCIAL = "sensor_social";
  
  
  private static final String DATABASE_NAME = "es.db";
  private static final int DATABASE_VERSION = 1;

  // Database creation sql statement
  private static final String DATABASE_CREATE = "create table "
      + TABLE_NAME + "(" + COLUMN_CAPTURE
      + " integer primary key autoincrement, " + COLUMN_IMAGE
      + " string, " + COLUMN_TEXT
      + " string, " + COLUMN_SENSOR_TEMP
      + " double, " + COLUMN_SENSOR_GSR
      + " double, " + COLUMN_SENSOR_HEARTRATE
      + " double, " + COLUMN_SENSOR_SOCIAL + " double );";

  public MySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  //only called the first time when database does not exist and called by update method
  public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w(MySQLiteHelper.class.getName(),
        "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(db);
  }
}
